//
// Created by isabella on 25-5-24.
//
#include <common.h>
#include <json.hpp>

class Solution {
public:
    int removeDuplicates(vector<int>& nums) {
        int left=0,right=0,r=INT_MIN,idx=0;
        while(right<nums.size()) {
            //初次初始化r
            if(nums[left]!=r) {
                r=nums[left];
            }
            if(nums[right]!=r) {
                nums[idx++]=nums[left];
                if(right-left>1) {
                    nums[idx++]=nums[left];
                }
                left=right;
            }else {
                right++;
            }
        }
        nums[idx++]=nums[left];
        if(right-left>1) {
            nums[idx++]=nums[left];
        }
        return idx;
    }
};

int main() {
    auto sp=new Solution();
    vector<int> nums{1,1,1,2,2,3};
    auto res= sp->removeDuplicates(nums);
    nlohmann::json j;
    j["vec"]=nums;
    j["res"]=res;
    cout<<j<<endl;
}